package controller;

import domain.Client;
import domain.SynchronizeThread;
import java.io.IOException;
import java.nio.file.InvalidPathException;

/**
 * The controller that handles the main functioning of the application
 *
 * @author Joachim
 */
public class ApplicationController {

    private Client client;

    /**
     * Constructor
     *
     * @param client The client the controller should talk to
     */
    public ApplicationController(Client client) {
        this.client = client;
    }

    /**
     * Calls the client to retrieve the root directory from the settings.
     *
     * @return The root directory
     */
    public String getRootDirectory() {
        return client.getRootDirectory();
    }

    /**
     * Calls the client to set the root directory.
     *
     * @param rootDirectory The root directory
     * @throws InvalidPathException When the rootdirectory doesn't exist or when
     * it's not a folder
     * @throws IOException When the directory listener can't register the root
     * directory
     */
    public void setRootDirectory(String rootDirectory) throws InvalidPathException, IOException {
        client.setRootDirectory(rootDirectory);
    }

    /**
     * Creates & starts a thread that will perform the initial sync of the client
     */
    public void performInitialSync() {
        new SynchronizeThread(client).start();
    }

    /**
     * Activates the directory listener: Start watching for changes.
     */
    public void activateDirectoryListener() {
        client.activateDirectoryListener();
    }

    /**
     * Deactivates the directory listener: Stop watching for changes.
     */
    public void deactivateDirectoryListener() {
        client.deactivateDirectoryListener();
    }
    
}
